#!/bin/bash

if [ -d "$HOME/Miao-Yunzai" ]; then
    lsy="$HOME/Miao-Yunzai"
    jh="$HOME/Miao-Yunzai/plugins"
    xrk="$HOME/xrk"
elif [ -d "$HOME/Yunzai-Bot" ]; then
    lsy="$HOME/Yunzai-Bot"
    jh="$HOME/Yunzai-Bot/plugins"
    xrk="$HOME/xrk"
elif [ -d "$HOME/yxybot" ]; then
    lsy="$HOME/yxybot"
    jh="$HOME/yxybot/plugins"
    xrk="$HOME/xrk"
else
    echo "您未安装机器人,记得通过脚本安装机器人哦"
fi

cd $HOME
echo "优先级自上而下递减"
echo -e "\\e[31m ！！！！！！！！版本过低！！！！！！！\\e[0m"
echo -e "\\e[34m =========================================== \\e[0m"
echo "1. 新版版本过低方案"
echo "2. 版本过低1(通过上传device.json)"
echo "3. 版本过低2(通过修改device.json的参数)"
echo "4. 版本过低3(通过上传device.json和token文件)"
echo "5. 返回"
echo -e "\\e[34m =========================================== \\e[0m"
read -p "选择一个吧: " choice

case $choice in
  1)
     if [ -d "$xrk" ]; then
         rm -rf $xrk
     fi
     if [ -f "$lsy/data/device.json" ]; then
         rm $lsy/data/device.json
     fi
     cd $lsy
     pnpm install icqq@0.2.1 -w
     cd $HOME 
     git clone --depth=1 https://gitee.com/xrk114514/shell-Yunzai.git  xrk/
     cp "$xrk/shell-version-issue/新方案/icqq0.2.0/device.js" "$lsy/node_modules/icqq/lib/core"
     echo "解决成功，请尝试用apad登录云崽"
     rm -rf xrk
     cd $lsy
     pnpm run login
     ;;
  2) echo "emoemo"
     read -p "请输入你的qq小号:" qq
     cd $HOME     
     git clone --depth=1 https://gitee.com/xrk114514/shell-Yunzai.git  xrk/
     if [ -f "$lsy/data/device.json" ]; then
         rm $lsy/data/device.json
     fi
     if [ -f "$lsy/data/$qq_token" ]; then
         rm $lsy/data/$qq_token
     fi
     mv $xrk/shell-version-issue/device.json $lsy/data/
     rm -rf $xrk
     cd $lsy
     npm run login ;;
  3) cd $lsy/data
     mv device.json device.json.txt
     sed -i 's/1/2/g' device.json.txt
     sed -i 's/0/9/g' device.json.txt
     sed -i 's/7/8/g' device.json.txt
     sed -i 's/5/6/g' device.json.txt
     sed -i 's/3/4/g' device.json.txt
     mv device.json.txt device.json
     cd $lsy
     pnpm run login ;;
  4) cd $HOME
     read -p "请输入你的qq小号:" qq
     git clone --depth=1 https://gitee.com/xrk114514/shell-Yunzai.git  xrk/
     if [ -f "$lsy/data/device.json" ]; then
         rm $lsy/data/device.json
     fi
     if [ -f "$lsy/data/$qq_token" ]; then
         rm $lsy/data/$qq_token
     fi
     mv "$xrk/shell-version-issue/device.json" "$lsy/data/"
     mv "$xrk/shell-version-issue/token" "$lsy/data/$qq_token"
     cd ~
     rm -rf xrk
     echo "正在重新配置账号"
     cd $lsy
     npm run login ;;
  5) exit 1 ;;
  *) echo -e "你乱点什么乱点"
esac